package com.hxd.otc.dialog;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.flyco.dialog.widget.internal.InternalBasePopup;
import com.hxd.otc.R;
import com.hxd.otc.common.enums.TakeOrderStatusEnum;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by lzy on 2018/9/15 0015.
 * description ${钱包菜单}
 */
public class TakeOrderStatusMenuPopupWindow extends BasePopupWindow<TakeOrderStatusMenuPopupWindow> {
    @BindView(R.id.fl_container)
    FrameLayout mFlContainer;
    @BindView(R.id.tv_content)
    TextView mTvContent;

    private OnSelectListener mOnSelectListener;
    private int mWidth;
    private TakeOrderStatusEnum mTakeOrderStatusEnum = TakeOrderStatusEnum.StopOrders;//无感广告商接单状态

    public TakeOrderStatusMenuPopupWindow(Context context) {
        super(context);
    }

    @Override
    public View onCreatePopupView() {
        return View.inflate(mContext, getLayoutId(), null);
    }

    protected int getLayoutId() {
        return R.layout.layout_menu_left;
    }

    @Override
    public void onViewCreated(View view) {
        super.onViewCreated(view);
        ButterKnife.bind(this, view);
    }

    public InternalBasePopup setWidth(int width) {
        mWidth = width;
        return this;
    }

    @Override
    public void setUiBeforShow() {
        ViewGroup.LayoutParams layoutParams = mFlContainer.getLayoutParams();
        layoutParams.width = mWidth;
        mFlContainer.setLayoutParams(layoutParams);
        mTvContent.setBackgroundResource(TakeOrderStatusEnum.InTheOrder.equals(mTakeOrderStatusEnum) ?
                R.drawable.shape_hovering_take_orders : R.drawable.shape_hovering_stop_orders);
        mTvContent.setText(TakeOrderStatusEnum.InTheOrder.equals(mTakeOrderStatusEnum) ? R.string.take_orders : R.string.stop_orders_lin_feed);
    }

    public TakeOrderStatusMenuPopupWindow setTakeOrderStatusEnum(TakeOrderStatusEnum takeOrderStatusEnum) {
        mTakeOrderStatusEnum = takeOrderStatusEnum;
        return this;
    }

    @OnClick(R.id.tv_content)
    public void onClick(View view) {
        if (mOnSelectListener != null) {
            mOnSelectListener.onSelected(mTakeOrderStatusEnum);
        }
    }

    public TakeOrderStatusMenuPopupWindow setOnSelectListener(OnSelectListener onSelectListener) {
        mOnSelectListener = onSelectListener;
        return this;
    }

    public interface OnSelectListener {
        void onSelected(TakeOrderStatusEnum mTakeOrderStatusEnum);
    }
}
